package com.cardone.common.beans.propertyeditors;

import com.cardone.common.util.DateUtils;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.beans.PropertyEditorSupport;

/**
 * 自定义时间绑定
 *
 * @author fand.cardone
 */
@Slf4j
public class CardOneDateEditor extends PropertyEditorSupport {
    @Setter
    private String[] parsePatterns;

    @Override
    public void setAsText(final String text) throws IllegalArgumentException {
        if (StringUtils.isBlank(text)) {
            return;
        }

        this.setValue(DateUtils.parseDate(text, this.parsePatterns));
    }
}
